package com.dhcc.core.modules.system.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.core.modules.system.dao.GroupMemberMapper;
import com.dhcc.core.modules.system.entity.GroupMember;
import com.dhcc.core.modules.system.service.IGroupMemberService;

/**
 * 群组成员表数据服务层接口
 * 
 * @ClassName: GroupMemberServiceImpl
 * @Description: TODO
 * @author lifan
 * @date 2018-08-21 15:30:14
 */
@Service("groupMemberService")
public class GroupMemberServiceImpl extends BaseServiceImpl<GroupMemberMapper, GroupMember> implements IGroupMemberService {
    
	@Override
	public List<GroupMember> list(Page<GroupMember> page, Map<String, Object> map) {
		return this.baseMapper.list(page, map);
	}
	
	@Transactional(rollbackFor = Exception.class)
	@Override
	public Boolean insertGroupMember(String user_id) {
		// TODO Auto-generated method stub
		String[]  user_ids=user_id.split(",");
        for(int i=1;i<user_ids.length;i++){
        	GroupMember groupMember=new GroupMember();
            groupMember.setGroupId(Long.parseLong(user_ids[0]));
        	groupMember.setUserId(Long.parseLong(user_ids[i]));
        	if(this.baseMapper.selectUserById(groupMember.getUserId())!=null){
        		if(this.baseMapper.selectGroupMember(groupMember)==null){
            		groupMember.insert();
            	}
        	}
        }
		return true;
	}

	

	
}